package com.yehongyu.mytools.ui.applet;

import java.applet.Applet;
import java.awt.Checkbox;
import java.awt.TextArea;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

public class CheckBoxApplet extends Applet implements ItemListener{

	/**序列ID*/
	private static final long serialVersionUID = 1L;

	TextArea t = new TextArea(6, 20);
	Checkbox cb1 = new Checkbox("Check Box 1");
	Checkbox cb2 = new Checkbox("Check Box 2");
	Checkbox cb3 = new Checkbox("Check Box 3");

	public void init() {
		add(t);
		add(cb1);
		add(cb2);
		add(cb3);
		cb1.addItemListener(this);
		cb2.addItemListener(this);
		cb3.addItemListener(this);
	}
	
	public void itemStateChanged(ItemEvent e) {
		if(e.getSource().equals(cb1)){
			t.append("Box 1 " + (cb1.getState()?"Checked":"Unchecked") + "\n");
		}else if(e.getSource().equals(cb2)){
			t.append("Box 2 " + (e.getStateChange()==1?"Checked":"Unchecked") + "\n");
		}else if(e.getSource().equals(cb3)){
			t.append("Box 3 " + (e.getStateChange()==1?"Checked":"Unchecked") + "\n");
		}else{
			t.append("Object is [" + e.getItem() + "],Unknow action\n");
		}
	}


}
